package com.guigu.www.controller.yinBo;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.guigu.www.dao.bean.*;
import com.guigu.www.service.TMemberExaminationService;
import com.guigu.www.service.TMemberService;
import com.guigu.www.service.TOrderInfoService;
import com.guigu.www.service.TOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author abo
 * @since 2021-06-22
 */
@RestController
@CrossOrigin
public class TOrderInfoController {


    @Autowired
    TOrderService tOrderService;
    @Autowired
    TOrderInfoService tOrderInfoService;
    @Autowired
    TMemberExaminationService tMemberExaminationService;

    @PostMapping("/tOrderInfo")
    public String q(@RequestParam(required = false) int memberId,
                    int setmealId,String name, String sex, String phoneNumber, String idCard, String time){

        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        TOrder tOrder = new TOrder();
        tOrder.setOrderDate(time);
        tOrder.setMemberId(memberId);
        tOrder.setSetmealId(setmealId);
        tOrder.setOrderStatus(0);
        tOrder.setCreatetime(format1.format(date));

        tOrderService.insertReturnKey(tOrder);

        int i = Integer.parseInt(sex);
        TOrderInfo tOrderInfo = new TOrderInfo();
        tOrderInfo.setName(name);
        tOrderInfo.setMemberId(memberId);
        tOrderInfo.setSetmealId(setmealId);
        tOrderInfo.setSex(i);
        tOrderInfo.setPhoneNumber(phoneNumber);
        tOrderInfo.setIdCard(idCard);
        tOrderInfo.setTime(time);

        tOrderInfoService.insert(tOrderInfo.setOrderId(tOrder.getId()));

        TMemberExamination tMemberExamination=new TMemberExamination();
        tMemberExamination.setTSetmealId(setmealId);
        tMemberExamination.setTMemberId(memberId);

        String times = format.format(date);
        tMemberExamination.setCreatetime(times);
        tMemberExaminationService.insert(tMemberExamination);

        return "提交预约完成";

    }


}

